{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "73f76495",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a2335844",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3 4\n",
      "1<2<3<4\n"
     ]
    }
   ],
   "source": [
    "print(1,2,3,4)#默认分隔符为空格\n",
    "print(1,2,3,4,sep=\"<\")#将分隔符改为箭头"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2f9a2d5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3\t1 2 3\n"
     ]
    }
   ],
   "source": [
    "print(1,2,3,end=\"\\t\")#\\t是制表符，为一个tab大小  默认为\\n 换行\n",
    "print(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a4533e65",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"1.tex\",\"w\")as f:#a为追加 w为覆盖\n",
    "  print(\"22222\",file=f)  #首行缩进！！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bff979a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "名字是01,今年年龄是18\n"
     ]
    }
   ],
   "source": [
    "name=\"01\" \n",
    "age=18#直接定义变量 不用管%d %S\n",
    "print(f\"名字是{name},今年年龄是{age}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8f3e2ecf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的内容是 1234\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a=input(\"请输入一些内容：\")\n",
    "print(\"您输入的内容是\",a)#要记得后面加上变量\n",
    "print(type(a))#<class 'str'>字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "69f5bae6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的内容是 123\n",
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a=int(input(\"请输入一些内容：\"))#强制转换变量类型\n",
    "print(\"您输入的内容是\",a)\n",
    "print(type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "522ecb9c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=11\n",
    "b=3\n",
    "c=a//b#//是整除  %求余数  **幂\n",
    "print(type(c))\n",
    "c#jupyter会默认输出最后一行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c0acf91b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.12"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(2.123123,2)#四舍五入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7160ae67",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a的值是1.25\n"
     ]
    }
   ],
   "source": [
    "a=1.254271\n",
    "print(f\"a的值是{a:.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3caa85c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'o'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1=\"hello world\"#索引查询 正数从0 倒数从-1开始\n",
    "str1[4]\n",
    "str1[-3]\n",
    "str1[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e0ab8a6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "eoo\n"
     ]
    }
   ],
   "source": [
    "str1=\"hello world\"#切片 [start：end：step]\n",
    "print(str1[::])\n",
    "print(str1[1:8:3])#性质为左闭又开"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
